﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpNewFeaturesUse
{
    public class SwitchExpression
    {
        /// <summary>
        /// 使用switch表达式来实现object到int的转化
        /// </summary>
        public static void ShowUse()
        {
            object obj = "1";
            object obj1 = 2;

            var result = convert(obj) + convert(obj1);
            
            Console.WriteLine($"Object1({obj.GetType()} {obj}) + Object1({obj1.GetType()} {obj1}) = {result}");
        }
        public static int convert(object obj)
        {
            return obj switch
            {
                int int1 => int1,
                string str => int.Parse(str),
                _ => throw new NotSupportedException()
            };
        }
    }
}